package com.ruoyi.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.domain.ZhwyDowntownVO;
import com.ruoyi.system.domain.ZhwyBuilding;
import com.ruoyi.system.mapper.ZhwyBuildingMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ZhwyDowntownMapper;
import com.ruoyi.system.domain.ZhwyDowntown;
import com.ruoyi.system.service.IZhwyDowntownService;

/**
 * 商业区信息管理Service业务层处理
 * 
 * @author nhh
 * @date 2024-05-04
 */
@Service
public class ZhwyDowntownServiceImpl implements IZhwyDowntownService 
{
    @Autowired
    private ZhwyDowntownMapper zhwyDowntownMapper;
    @Autowired
    private ZhwyBuildingMapper zhwyBuildingMapper;

    /**
     * 查询商业区信息管理
     * 
     * @param id 商业区信息管理主键
     * @return 商业区信息管理
     */
    @Override
    public ZhwyDowntown selectZhwyDowntownById(Long id)
    {
        return zhwyDowntownMapper.selectZhwyDowntownById(id);
    }

    @Override
    public int del(Long[] ids) {
        return zhwyDowntownMapper.del(ids);
    }

    @Override
    public int canceldel(Long id) {
        return zhwyDowntownMapper.canceldel(id);
    }

    /**
     * 查询商业区信息管理列表
     * 
     * @param zhwyDowntown 商业区信息管理
     * @return 商业区信息管理
     */
    @Override
    public List<ZhwyDowntownVO> selectZhwyDowntownList(ZhwyDowntown zhwyDowntown)
    {
        List<ZhwyDowntown> dts = zhwyDowntownMapper.selectZhwyDowntownList(zhwyDowntown);
        List<ZhwyDowntownVO> list = new ArrayList<>();

        for (ZhwyDowntown dt : dts){
            ZhwyBuilding zhwyBuilding = new ZhwyBuilding();
            zhwyBuilding.setdId(dt.getId());
            List<ZhwyBuilding> zhwyBuildings = zhwyBuildingMapper.selectZhwyBuildingList(zhwyBuilding);

            ZhwyDowntownVO zhwyDowntownVO = new ZhwyDowntownVO();
            BeanUtils.copyProperties(dt, zhwyDowntownVO);
            zhwyDowntownVO.setZhwyBuildingList(zhwyBuildings);

            list.add(zhwyDowntownVO);
        }

        return list;
    }

    /**
     * 新增商业区信息管理
     * 
     * @param zhwyDowntown 商业区信息管理
     * @return 结果
     */
    @Override
    public int insertZhwyDowntown(ZhwyDowntown zhwyDowntown)
    {
        return zhwyDowntownMapper.insertZhwyDowntown(zhwyDowntown);
    }

    /**
     * 修改商业区信息管理
     * 
     * @param zhwyDowntown 商业区信息管理
     * @return 结果
     */
    @Override
    public int updateZhwyDowntown(ZhwyDowntown zhwyDowntown)
    {
        return zhwyDowntownMapper.updateZhwyDowntown(zhwyDowntown);
    }

    /**
     * 批量删除商业区信息管理
     * 
     * @param ids 需要删除的商业区信息管理主键
     * @return 结果
     */
    @Override
    public int deleteZhwyDowntownByIds(Long[] ids)
    {
        return zhwyDowntownMapper.deleteZhwyDowntownByIds(ids);
    }

    /**
     * 删除商业区信息管理信息
     * 
     * @param id 商业区信息管理主键
     * @return 结果
     */
    @Override
    public int deleteZhwyDowntownById(Long id)
    {
        return zhwyDowntownMapper.deleteZhwyDowntownById(id);
    }
}
